package ar.org.cfired.seguridad;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import ar.org.cfired.creditos.seguridad.*;

import java.util.List;

public class CargarPasswords {
	public static void main(String args[]) {
		SessionFactory sessionFactory = new org.hibernate.cfg.Configuration().configure("hib.cfg.xml").buildSessionFactory();
		Session session = sessionFactory.getCurrentSession();
		session.beginTransaction();
		Query q = session.createSQLQuery("select distinct id_, password_ from jbpmCreditos.dbo.jbpm4_id_user where id_='cuil20287559810_4'" );
		List<Object[]> rta = q.list();
		Object[] obj;
		GestorDeClaves g;
		for (int i = 0; i<rta.size(); i++) {
			obj = rta.get(i);
			System.out.println("Usuario " + String.valueOf(obj[0]) + " - pwd: " + String.valueOf(obj[1]));
			Session sess = sessionFactory.getCurrentSession();
			g = new GestorDeClaves(sess);
			g.guardar(String.valueOf(obj[0]), String.valueOf(obj[1]));
		
		}
		if (session.isOpen())
			session.getTransaction().rollback();
	}
}
